package com.sig.formes;
import java.util.ArrayList;
import java.util.List;

import utils.Polygon;

import android.util.Log;


public class Polyedre extends Forme{

	public List<Point> points = new ArrayList<Point>(); 
	public List<Triangle> triangles = new ArrayList<Triangle>(); 

	List<Segment> bordures = null;

	///////////////////:CONSTRUCTEUR:////////////////////////////
	public Polyedre(float[] color,Point...points){
		ArrayList<Point> out = new ArrayList<Point>();
		for(Point p:points){
			out.add(p);
		}
		creer(out,color);
	}

	public Polyedre(List<Point> points,float[] color) {
		creer(points,color);
	}

	/////////////////////:CONVERSION://////////////////////////////
	public static Polyedre convert(Polygon polygon, float[] color)
	{
		List<utils.Point> ps = polygon.getPoly();
		List<Point> pointPoly = new ArrayList<Point>();
		for(utils.Point p : ps){
			pointPoly.add(new Point(p.getX(), p.getY()));
		}
		return new Polyedre(pointPoly, color);
	}
	///////////////////:OPENGL:///////////////////////////////////
	private void creer(List<Point> points,float[] color){
		this.points = points;
		this.color = color;
		this.triangles = EarCuttingSimply.trianguler(this);
	}

	public void dessinerBordure(float [] mvpMatrix){
		if(bordures == null){
			bordures = Segment.pointToList(this.points);
			for (Segment segment : bordures) {
				Log.e("Polyedre","dessin bordure");
				segment.epaisseur = 1f;
				segment.color = Forme.bleu;
				segment.dessinerBord = false;
			}
		}
		for (int i = 0 ; i < bordures.size() ; i+=2) {
			bordures.get(i).draw(mvpMatrix);
		}
	}

	@Override
	public void recreer(){
		super.recreer();
	}

	public List<Point> getPoints() {
		return points;
	}

	public void setPoints(List<Point> points) {
		this.points = points;
	}

	public List<Triangle> getTriangles() {
		return triangles;
	}

	public void setTriangles(List<Triangle> triangles) {
		this.triangles = triangles;
	}
}
